package cn.yzgy.yzgyoa.ucenter.controller;


import cn.yzgy.yzgyoa.common.annotation.ApiDesc;
import cn.yzgy.yzgyoa.common.annotation.EnableDict;
import cn.yzgy.yzgyoa.common.annotation.Syslog;
import cn.yzgy.yzgyoa.common.crsp.Urmf;
import cn.yzgy.yzgyoa.ucenter.dto.SysStaffDTO;
import cn.yzgy.yzgyoa.ucenter.service.ISysStaffService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import cn.yzgy.yzgyoa.common.controller.BaseController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Yqsen
 * @since 2021-06-03
 */
@Slf4j
@Syslog
@RestController
@RequestMapping("/ucenter/sys-staff")
public class SysStaffController extends BaseController {

    private final ISysStaffService sysStaffService;

    public SysStaffController(ISysStaffService sysStaffService) {
        this.sysStaffService = sysStaffService;
    }

    @ApiDesc("分页获取员工列表")
    @GetMapping("/getAllStaff")
    @EnableDict
    @RequiresPermissions("api:staff:staffList:getAllStaff")
    public Urmf getAllStaff(@RequestParam Integer page, @RequestParam Integer size, SysStaffDTO queryDto) {
        IPage<SysStaffDTO> staffPage = sysStaffService.getAllStaff(new Page<>(page, size), queryDto);
        return Urmf.success(getCurrentMethodName(), staffPage);
    }

    @ApiDesc("新增员工")
    @PostMapping("/addStaff")
    @RequiresPermissions("api:staff:staffList:addStaff")
    @ResponseBody
    public Urmf addStaff(@RequestBody SysStaffDTO queryDto) {
        boolean state = sysStaffService.addStaff(queryDto,getCurrentUser());
        if(state){
            return Urmf.success(getCurrentMethodName(), "新增成功");
        }
        return Urmf.fail(getCurrentMethodName(), "新增失败");
    }

    @ApiDesc("修改员工资料")
    @PutMapping("/editStaff")
    @RequiresPermissions("api:staff:staffList:editStaff")
    @ResponseBody
    public Urmf editStaff(@RequestBody SysStaffDTO queryDto) {
        boolean state = sysStaffService.editStaff(queryDto,getCurrentUser());
        if(state){
            return Urmf.success(getCurrentMethodName(), "修改成功");
        }
        return Urmf.fail(getCurrentMethodName(), "修改失败");
    }

    @ApiDesc("设置员工离职状态")
    @PostMapping("/delStaff")
    @RequiresPermissions("api:staff:staffList:delStaff")
    @ResponseBody
    public Urmf delStaff(@RequestBody SysStaffDTO queryDto) {
        boolean state = sysStaffService.delStaff(queryDto,getCurrentUser());
        if(state){
            return Urmf.success(getCurrentMethodName(), "设置员工离职状态成功");
        }
        return Urmf.fail(getCurrentMethodName(), "设置员工离职状态失败");
    }
}
